﻿#ifndef HRIBBONGALLERYGROUP_H
#define HRIBBONGALLERYGROUP_H
#include "HRibbonGlobal.h"
#include <QList>
#include "HRibbonGalleryItem.h"
#include <QListView>
#include <QStyledItemDelegate>
#include "HRibbonGalleryItem.h"


///
/// \brief HRibbonGalleryGroup对应的显示代理
///
class HRIBBON_EXPORT HRibbonGalleryGroupItemDelegate : public QStyledItemDelegate
{
public:
    HRibbonGalleryGroupItemDelegate(HRibbonGalleryGroup *group, QObject *parent = Q_NULLPTR);
    virtual void paint(QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index) const Q_DECL_OVERRIDE;

    virtual QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const Q_DECL_OVERRIDE;
    virtual void paintIconOnly(QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
    virtual void paintIconWithText(QPainter *painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;

private:
    HRibbonGalleryGroup *m_group;
};

///
/// \brief HRibbonGalleryGroup对应的model
///
class HRIBBON_EXPORT HRibbonGalleryGroupModel : public QAbstractListModel
{
    Q_OBJECT
public:
    HRibbonGalleryGroupModel(QObject *parent = Q_NULLPTR);
    ~HRibbonGalleryGroupModel();
    virtual int rowCount(const QModelIndex& parent) const Q_DECL_OVERRIDE;
    virtual Qt::ItemFlags flags(const QModelIndex& index) const Q_DECL_OVERRIDE;
    virtual QVariant data(const QModelIndex& index, int role) const Q_DECL_OVERRIDE;
    virtual QModelIndex index(int row, int column, const QModelIndex& parent) const Q_DECL_OVERRIDE;
    virtual bool setData(const QModelIndex& index, const QVariant& value, int role) Q_DECL_OVERRIDE;
    void clear();
    HRibbonGalleryItem *at(int row) const;
    void insert(int row, HRibbonGalleryItem *item);
    HRibbonGalleryItem *take(int row);
    void append(HRibbonGalleryItem *item);

private:
    QList<HRibbonGalleryItem *> m_items;
};



class HRibbonGalleryGroupPrivate;
///
/// \brief Gallery的组
///
/// 组负责显示管理Gallery Item，
///

class HRIBBON_EXPORT HRibbonGalleryGroup : public QListView
{
    Q_OBJECT
    Q_PROPERTY(bool enableIconText READ enableIconText WRITE setEnableIconText)
public:
    ///
    /// \brief 预设样式
    ///
    enum PreinstallStyle {
        LargeIconWithText ///< 大图标带文字
        , LargeIconOnly
    };

    HRibbonGalleryGroup(QWidget *w = 0);

    virtual ~HRibbonGalleryGroup();
    void setPreinstallStyle(PreinstallStyle style);
    void addItem(const QString& text, const QIcon& icon);
    void addItem(HRibbonGalleryItem *item);
    void addActionItem(QAction *act);
    void addActionItemList(const QList<QAction *>& acts);

    //构建一个model，这个model的父类是HRibbonGalleryGroup，如果要共享model，需要手动处理model的父类
    void setupGroupModel();
    HRibbonGalleryGroupModel *groupModel();

    //是否在Gallery的图标下显示文字
    void setEnableIconText(bool enable);
    bool enableIconText() const;
    void setGroupTitle(const QString& title);
    QString groupTitle() const;
    void selectByIndex(int i);

private slots:
    void onItemClicked(const QModelIndex& index);

signals:
    void groupTitleChanged(const QString& title);

private:
    HRibbonGalleryGroupPrivate *m_d;
};


#endif // HRIBBONGALLERYGROUP_H
